setRetainInstance

open fun setRetainInstance(retain: Boolean)(source)

Deprecated

Instead of retaining the Fragment itself, use a non-retained Fragment and keep retained state in a ViewModel attached to that Fragment. The ViewModel's constructor and its onCleared() callback provide the signal for initial creation and final destruction of the retained state.

Control whether a fragment instance is retained across Activity re-creation (such as from a configuration change). If set, the fragment lifecycle will be slightly different when an activity is recreated:

Parameters

retain

true to retain this fragment instance across configuration changes, false otherwise.

See also